//
//  PCMainManager.m
//  PromotionCode
//
//  Created by baken on 2017/10/24.
//  Copyright © 2017年 My. All rights reserved.
//

#import "PCMainManager.h"
#import "PCMainCategoryModel.h"
#import "PCMainListModel.h"
#import "PCGoodsDetailModel.h"
#import "PCMainRecommendListModel.h"
#import "PCRecommendDetailModel.h"


@implementation PCMainManager


+(void)getCategoryWithCompletionHandle:(void (^)(PCMainCategoryModel *model, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@",Api_URL,kGetHotCategory]
    parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCMainCategoryModel *model = [PCMainCategoryModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}

+(void)getMainListWithCategoryID:(NSString *)categoryID andPageNum:(NSString *)pageNum andCompletionHandle:(void (^)(PCMainListModel *model, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?p=%@&class=%@",Api_URL,kGetMainList,pageNum,categoryID]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCMainListModel *model = [PCMainListModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}


+(void)getMainRecommendListWithPageNum:(NSString *)pageNum andCompletionHandle:(void (^)(PCMainRecommendListModel *model, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?p=%@&article_id=1",Api_URL,kGetRecommend,pageNum]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCMainRecommendListModel *model = [PCMainRecommendListModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}

+(void)getGoodsDetailWithGoodsID:(NSString *)goodsID andCompletionHandle:(void (^)(GoodsDetailModel *model, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?num_iid=%@",Api_URL,kGetGoodsDetail,goodsID]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCGoodsDetailModel *model = [PCGoodsDetailModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model.output,error);
}];

}

+(void)getDetailRecommendListWithCompletionHandle:(void (^)(PCMainListModel *model, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?p=1",Api_URL,kDetailRecommend]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCMainListModel *model = [PCMainListModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}


+(void)getRecommendDetailWithRecommendID:(NSString *)recommendID CompletionHandle:(void (^)(PCRecommendDetailModel *model, NSError *error))complete{
    [self POST:[NSString stringWithFormat:@"%@%@?article_id=%@",Api_URL,kGetNewsDetail,recommendID]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
    PCRecommendDetailModel *model = [PCRecommendDetailModel mj_objectWithKeyValues:responseObj];
    if (model.error_code != 0) {
        error = [self createError:model.error_msg];
    }
    complete(model,error);
}];
}


@end
